{% extends 'layout.html' %}

{% block content %}
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <!-- /.box-header -->
                <div class="box-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="control-label col-md-2">任务名称<span class="red">&nbsp;*&nbsp;</span>:</label>
                            <div class="col-md-10">
                                <input id="tgt" name="tgt" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="fastpush-box">
                            <div class="fastpush-box-header">
                                <span class="box-header-title"><i class="fa fa-database"></i> 源文件</span>
                                <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注意：本地文件上传会有同名文件覆盖风险</span>
                                <span class="priview-span ps1" data-toggle="tooltip" data-placement="right" title=""
                                      data-original-title="文件名不能包含中文字符，且文件大小不能超过500M">
							<i class="fa fa-question-circle"></i></span>
                                <div class="pull-right pt10">
                                    <a id="localFile" class="btn btn-info fileinput-button" type="button"><i
                                            class="fa fa-upload"></i> 添加本地文件
                                        <input id="fileUpload" name="upload" type="file" multiple="multiple">
                                    </a>
                                    <button id="remoteFileEditBut" class="btn btn-info" type="button"><i
                                            class="fa fa-cloud"></i> 添加服务器文件
                                    </button>
                                </div>
                            </div>
                            <div class="pt5" id="fileSource">
                                <table class="table table-bordered table-hover fileSourceTable" data-content="必填项">
                                    <thead>
                                    <tr style="background: #f6f8f8; border-top: 2px solid rgb(74, 155, 255) !important;">
                                        <th style="width: 30%;">文件列表</th>
                                        <th style="width: 25%;">服务器地址</th>
                                        <th style="width: 25%;">执行账户</th>
                                        <th style="width: 20%;">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr class="blankTr">
                                        <td colspan="4" style="text-align: center;">请添加源文件！
                                            <input type="hidden" class="fileSource">
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div style="height: 20px"></div>
                        <div class="fastpush-box">
                            <div class="fastpush-box-header">
					            <span class="box-header-title">
					            <i class="fa fa-inbox"></i> 目标文件
					            </span>
                            </div>
                            <div class="form-group" style="padding-top: 7px;">
                                <label class="control-label col-md-2">目标路径<span
                                        class="red">&nbsp;*</span>：</label>
                                <div class="col-md-10" data-content="必填项">
                                    <input type="text" style="width:607px;display: inline-block"
                                           class="form-control" name="txtTargetFilePath" id="txtTargetFilePath"
                                           placeholder="请填写分发路径" maxlength="255">
                                    <span data-toggle="tooltip" data-placement="top"
                                          title="" data-html="true" data-original-title="<div class='t1' style='width:500px;text-align:left;'>如果该路径不存在，系统将自动创建。<br/>文件传输目的地址的路径规则：<br/>
                            linux服务器需以 / 开头的绝对路径。例如:/data/xx<br/>windows服务器必须包含盘符开头，例如：D:\tmp\</div>">
							<i class="fa fa-question-circle"></i>
						</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="control-label col-md-2">执行账户<span
                                        class="red">&nbsp;*</span>：</label>
                                <div class="col-md-10">
                                    <select id="userAccount" class="ijobs-user-account"
                                            style="width: 607px; display: none;">
                                        <option></option>
                                    </select>
                                    <div class="chosen-container chosen-container-single" style="width: 607px;"
                                         title="" id="userAccount_chosen">
                                        <a class="chosen-single chosen-default" tabindex="-1"><span>请选择</span>
                                            <div><b></b></div>
                                        </a>
                                        <div class="chosen-drop">
                                            <div class="chosen-search"><input type="text" autocomplete="off"></div>
                                            <ul class="chosen-results"></ul>
                                            <div class="chosen-operate newTask" href="./app/newTask.jsp"
                                                 style="display:none;">+新建作业
                                            </div>
                                        </div>
                                    </div>
                                    <button id="addUserBut" class="btn btn-success" type="button" title="登记新账户"><i
                                            class="fa fa-plus"></i></button>
                                    <div class="form-group" style="margin: 10px 0px 0px 0px;">
                                        <div style="display: none;" id="regUserDiv">
                                            <div class="well mb5">
                                                <div class="form-group" style="margin-bottom: 0;">
                                                    <div class="col-sm-12">
                                                        <label class="col-sm-3 control-label">账户名称<span class="red">&nbsp;*</span>：</label>
                                                        <div class="col-sm-6">
                                                            <input id="userName_input" type="text"
                                                                   class="form-control" aria-required="true"
                                                                   placeholder="请输入账户名称">
                                                        </div>
                                                        <div class="col-sm-3">
                                                            <button type="button" id="regUser"
                                                                    class="btn btn btn-primary">登记账户
                                                            </button>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <label id="resultMsg" style="color: red"
                                                               class="col-sm-6 col-sm-offset-2 control-label"></label>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="control-label col-md-2">目标机器<span
                                        class="red">&nbsp;*</span>：</label>
                                <div class="col-md-10" id="iplist">
                                    <div class="serverIp-Model-IsExist">
                                        <div class="row ml0 buttonGroup serverIpMode-1" style="width: 650px;">
                                            <input type="hidden" class="hidden-serverSetId">
                                            <input type="hidden" class="hidden-serverip-string">
                                            <div class="col-sm-4 p0">
                                                <button id="btn_chosen" type="button" class="btn btn-success showModel"
                                                        style="width: 115px"><i class="fa fa-desktop"></i>&nbsp;选择服务器
                                                </button>
                                            </div>
                                        </div>


                                    </div>
                                </div>
                            </div>

                        </div>
                        <div class="form-group">
                            <div class="col-md-12">
                                <button id="btn_exec" class="btn btn-success pull-right">
                                    <i class="fa fa-life-saver"></i> 执行
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block self_footer_js %}
    <script>
        // add button
        $("#btn_chosen").click(function () {
            var addDialog = new BootstrapDialog({
                title: "新建定时任务",
                closable: false,
                draggable: true,
                message: function (dialog) {
                    var $message = $('<div></div>');
                    var pageToLoad = dialog.getData('pageToLoad');
                    $message.load(pageToLoad);
                    return $message;
                },
                data: {
                    'pageToLoad': "{% url 'chosen_server' %}"
                },
                buttons: [{
                    cssClass: "btn-default",
                    label: "保存",
                    action: function (dialogItself) {
                        $.post($("#group_form").attr("action"), $("#group_form").serializeArray(), function (data) {
                            if (data.code == 1) {
                                $table.bootstrapTable("refresh");
                                dialogItself.close();
                                addDialog.close();
                            }
                            else BootstrapDialog.alert(data.message);
                        }, "json");
                        //$("#groupForm").validate();
                    }
                }, {
                    cssClass: 'btn-white',
                    label: "取消",
                    action: function (dialogItself) {
                        dialogItself.close();
                    }
                }]
            });
            addDialog.open();
        });
    </script>
{% endblock %}